<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2.axios的常用配置项.html
    </title>
</head>
<body>
    <button id="btn">发送axios请求</button>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.1/jquery.js"></script>

     <script>
         const  data ={
             username: "Alice",
             age:12,
             gender: 'girl'
         }

         /*axios全局默认配置*/
         axios.defaults.baseURL="http://127.0.0.1/axios";
         axios.defaults.timeout =2000;
         axios.defaults.headers={spm:"cbdshiugbdiuvb"};

         $("#btn").click(()=>{
             axios({
                 url:"/get",
                 method: 'get',
                 params:data,
                 timeout: 2000,
                 headers: {id:"fvdjsiofhniuuuuuuubu"},
                 responseType: 'json'
             }).then(
                 response =>{
                     console.log(response.data);
                 },
                 error =>{
                     console.log(error);
                 }
             )

         })




     </script>

</body>
</html>